/*************************
*IV_do_1ststage         **
*************************/
#delimit;
capture drop resid*;
eststo clear;
qui eststo: reghdfe T1 $spec3 $instrument_avg  if numberstudents_e>=5 & numberstudents_m>=5, a(sch_id) cluster(sch_id) res(reside1);
test $instrument_avg;
estadd scalar fs = r(F);estadd scalar nst = round(e(N),10);

qui eststo: reghdfe T2 $spec3 $instrument_avg if numberstudents_e>=5 & numberstudents_m>=5, a(sch_id) cluster(sch_id) res(residm1);
test $instrument_avg;
estadd scalar fs = r(F);estadd scalar nst = round(e(N),10);

qui eststo: reghdfe T1 $spec3 $instrument3 $instrument4 $instrument5, a(sch_id) cluster(sch_id) res(reside2);
test $instrument3 $instrument4 $instrument5;
estadd scalar fs = r(F);estadd scalar nst = round(e(N),10);

qui eststo: reghdfe T2 $spec3 $instrument3 $instrument4 $instrument5, a(sch_id) cluster(sch_id) res(residm2);
test $instrument3 $instrument4 $instrument5;
estadd scalar fs = r(F);estadd scalar nst = round(e(N),10);

qui eststo: reghdfe T1 $spec3 $instrument_avg $instrument3 $instrument4 $instrument5  if numberstudents_e>=3 & numberstudents_m>=3, a(sch_id) cluster(sch_id) res(reside3);
test $instrument3 $instrument4 $instrument5 $instrument_avg;
estadd scalar fs = r(F);estadd scalar nst = round(e(N),10);

qui eststo: reghdfe T2 $spec3 $instrument_avg $instrument3 $instrument4 $instrument5  if numberstudents_e>=3 & numberstudents_m>=3, a(sch_id) cluster(sch_id) res(residm3);
test $instrument3 $instrument4 $instrument5 $instrument_avg;
estadd scalar fs = r(F);estadd scalar nst = round(e(N),10);

esttab, stats(r2 r2_a nst fs);
esttab using $table\table_s14, append cells(b(fmt(2) star) se(fmt(2) par)) starlevels(* 0.10 ** 0.05 *** 0.01) 
label keep(tchavg_col_mb tchavg_col_eb passive_eng passive_math  never_attentive_eng rarely_attentive_eng some_attentive_eng mostly_attentive_eng 
never_attentive_math rarely_attentive_math some_attentive_math mostly_attentive_math sa_read_fun a_read_fun d_read_fun sa_math_fun a_math_fun d_math_fun) 
stats(r2 r2_a nst fs, fmt(2 2 0 2) labels(" $ R^2$ " "Adjusted $ R^2$ " "N" "F-test")) title(The Teacher Expectation Production Function, with School FE) 
mlabel("English" "Math" "English" "Math" "English" "Math");


